package com.yeyv.net.Security;

import com.yeyv.net.Web.Entity.AccountEntity;
import com.yeyv.net.Web.Service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyDetailService implements UserDetailsService {
    @Autowired
    private AccountService accountService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        AccountEntity account = accountService.getAccount(username);
        if (account == null) {
            throw new RuntimeException("用户名或密码错误");
        }
        LoginUser loginUser = new LoginUser();
        loginUser.setUserEntity(account);
        return loginUser;
    }
}
